export const Util = {
    int2Date: (value) => {
        const val = Number(value);
        if (isNaN(val)) {
            return;
        }
        const d = new Date(val);
        return d.getFullYear()
            + "-" + Util.padStart(d.getMonth(), 2, "0")
            + "-" + Util.padStart(d.getDate(), 2, "0")
            + " " + Util.padStart(d.getHours(), 2, "0")
            + ":" + Util.padStart(d.getMinutes(), 2, "0")
            + ":" + Util.padStart(d.getSeconds(), 2, "0");
    },
    padStart: (str, len = 0, pad = " ") => {
        if (str === undefined || (str + "").length >= len) {
            return str;
        }
        str = (str + "");
        let dis = len - str.length,
            padLen = pad.length;
        const times = Math.floor(dis / padLen) || 0,
            cutLength = dis % padLen;
        for (let i = 0; i < times; i++) {
            str = pad + str;
        }
        cutLength > 0 && (str = pad.substr(0, cutLength) + str);
        return str;
    },
    getReqHandleAction: (field) => (state, action) => (action.payload && action.payload.flag == 200 ? state.set(field, action.payload.result) : state.set(field, {}))
};

export default Util;